package com.example.hanfu;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class BitMapUtil {

        private static Bitmap bitmap;

        public static Bitmap returnBitMap(final String url) {
            if(url==null){
               return null;
            }else{
               new Thread(new Runnable() {
                    @Override
                    public void run() {
                        URL imageurl = null;

                        try {
                            imageurl = new URL(url);
                        } catch (MalformedURLException e) {
                            e.printStackTrace();
                        }
                        try {
                            HttpURLConnection conn = (HttpURLConnection) imageurl.openConnection();
                            conn.setDoInput(true);
                            conn.connect();
                            InputStream is = conn.getInputStream();
                            bitmap = BitmapFactory.decodeStream(is);
                            is.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();

            return bitmap;
        }
}

}
